package com.doitedu.utils

import org.apache.spark.Partitioner

/**
 * @Date: 22.7.1 
 * @Author: HANGGE
 * @qq: 598196583
 * @Tips: 学大数据 ,到多易教育
 * @Description:
 */
class MyPartitioner(numberPartitions: Int) extends Partitioner {
  override def numPartitions: Int = numberPartitions

  /**
   * 小于等于2的数据分到0号区
   * 其他的分到1号区
   *
   * @param key
   * @return
   */
  override def getPartition(key: Any): Int = {
    val str = key.asInstanceOf[String]
    val value = str.toInt
    if (value <= 3) {
      0
    } else {
      1
    }
  }
}
